﻿<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeBehind="Default.aspx.cs" Inherits="WebApplication2._Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:ScriptManager ID="scriptManager" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="upNewGame" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
            <asp:Button ID="buttonStartNewGame" runat="server" Text="Start New Game" OnClick="buttonStartNewGame_Click" />
            <asp:Panel ID="panelCreateNewGame" runat="server" Visible="false">
                <asp:Label ID="labelEnterPlayerName" runat="server" Text="Enter your name"></asp:Label>
                <asp:TextBox ID="ownerPlayerName" runat="server"></asp:TextBox>
                <asp:Button ID="buttonCreateGame" runat="server" Text="Create" OnClick="buttonCreateGame_Click" />
            </asp:Panel>
        </ContentTemplate>
    </asp:UpdatePanel>
    <br />
    <asp:Timer ID="timerRefreshGames" runat="server" OnTick="timerRefreshGames_Tick"
        Enabled="true" Interval="1000">
    </asp:Timer>
    <asp:Label ID="labelActiveGames" runat="server" Text="Active Games"></asp:Label>
    <br />
    <asp:UpdatePanel ID="upActiveGames" runat="server">
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="buttonCreateGame" EventName="Click" />
            <asp:AsyncPostBackTrigger ControlID="timerRefreshGames" EventName="Tick" />
        </Triggers>
        <ContentTemplate>
            <asp:Panel ID="panelJoinGame" runat="server" Visible="false">
                <asp:Label ID="labelJoinGameName" runat="server" Text="Please enter your name and join again"></asp:Label>
                <asp:TextBox ID="joinPlayerName" runat="server"></asp:TextBox>
            </asp:Panel>
            <asp:Repeater ID="repeaterActiveGames" runat="server">
                <HeaderTemplate>
                    <table>
                        <tr>
                            <th>
                                Player One
                            </th>
                            <th>
                                Player Two
                            </th>
                            <th>
                                Status
                            </th>
                        </tr>
                </HeaderTemplate>
                <ItemTemplate>
                    <tr>
                        <td bgcolor="#465c71">
                            <asp:Label runat="server" ID="labelFirstPlayer" Text='<%# GetUserName("User1ID") %>' ForeColor="White"
                                Font-Bold="true" />
                        </td>
                        <td bgcolor="#465c71">
                            <asp:Label runat="server" ID="labelSecondPlayer" Text='<%# GetUserName("User2ID") %>'
                                ForeColor="White" Font-Bold="true" />
                        </td>
                        <td bgcolor="#465c71">
                            <asp:Label runat="server" ID="labelResult" Text='<%# Eval("GameState") %>' ForeColor="White"
                                Font-Bold="true" />
                        </td>
                        <td>
                            <asp:Button ID="buttonJoinGame" runat="server" CommandArgument='<%# Eval("ID") %>'
                                OnCommand="joinGame" Text="Join" Visible='<%# GetUserName("User2ID")=="Empty"  %>' />
                        </td>
                    </tr>
                </ItemTemplate>
                <FooterTemplate>
                    </table>
                </FooterTemplate>
            </asp:Repeater>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
